

#include "data_global.h"

extern pthread_mutex_t mutex_fan;
extern pthread_cond_t cond_fan;
extern unsigned char cmd_fan;
// 串口设备文件描述符
extern int ttyUSB0fd;

// Zigbee风扇控制线程
void *pthread_fan(void *arg)
{
	printf("pthread_fan\n");
	while (1)
	{
		pthread_mutex_lock(&mutex_fan);
		pthread_cond_wait(&cond_fan, &mutex_fan);
		char cmdbuf[4] = {0};
		if (cmd_fan == 0x21)
		{
			strcpy(cmdbuf, "00\n");
			write(ttyUSB0fd, cmdbuf, sizeof(cmdbuf) / sizeof(cmdbuf[0]));
		}
		if (cmd_fan == 0x20)
		{
			strcpy(cmdbuf, "11\n");
			write(ttyUSB0fd, cmdbuf, sizeof(cmdbuf) / sizeof(cmdbuf[0]));
		}
		pthread_mutex_unlock(&mutex_fan);
	}
}
